package org.jwflow.design.utils;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.commons.dbutils.QueryRunner;
import io.gitee.yaoshanli.engine.db.JwDbHelper;
import io.gitee.yaoshanli.engine.utils.ConfigUtils;

import javax.sql.DataSource;
import java.util.Properties;

public class JDBCUtils {

    public static QueryRunner runner;

    public static void getRunner()
    {
        Properties prop = ConfigUtils.getProperties();
        getRunner(prop);
    }
    public static void getRunner(Properties prop)
    {
        //获取数据连接池对象
        DataSource dataSource = null;
        try {
            dataSource = DruidDataSourceFactory.createDataSource(prop);
        } catch (Exception e) {
            e.printStackTrace();
        }

        JwDbHelper.initialize(dataSource);
        runner=JwDbHelper.getRunner();
    }

    public void close()
    {
        JwDbHelper.close();
    }
}
